package com.ruoyi.ipms_patent.service.impl;

import com.ruoyi.ipms_patent.entity.CaseHistory;
import com.ruoyi.ipms_patent.mapper.CaseHistoryMapper;
import com.ruoyi.ipms_patent.service.CaseHistoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*案件历史业务实现类*/
@Service
public class CaseHistoryServiceImpl implements CaseHistoryService {

    @Resource
    private CaseHistoryMapper mapper;

    @Override
    public CaseHistory addCaseHistory(CaseHistory history) {
        int result = mapper.insertOne(history);
        return result > 0 ? history : null;
    }

    @Override
    public List<CaseHistory> findCaseHistoryList(Integer caseId) {
        return  mapper.selectList(caseId);
    }


    /* 插入案件历史记录 */
    @Override
    public int insertCaseHistory(List<Integer> caseIds, String caseHistoryStatusDescrip ) {
        String caseHistoryStatusId = "";
        if(caseHistoryStatusDescrip.equals("待撰稿")){
            caseHistoryStatusId = "1";
        }else if(caseHistoryStatusDescrip.equals("待初审")){
            caseHistoryStatusId = "2";
        }else if(caseHistoryStatusDescrip.equals("待复审")){
            caseHistoryStatusId = "3";
        }else if(caseHistoryStatusDescrip.equals("待官方回复")){
            caseHistoryStatusId = "5";
        }else if(caseHistoryStatusDescrip.equals("驳回")){
            caseHistoryStatusId = "6";
        }else if(caseHistoryStatusDescrip.equals("立案")){
            caseHistoryStatusId = "0";
        }

        for (int caseId : caseIds){
            mapper.insertCaseHistory(caseId,caseHistoryStatusId );
        }
        return 1;
    }

    /*全部案件历史列表分页（根据案件编号）*/
    @Override
    public List<CaseHistory> findListByCaseNo(String caseNo) {
        return mapper.findListByCaseNo(caseNo);
    }
}
